<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>Poll connections</title>

 </head>
 <body><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqli.ping.html">mysqli::ping</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqli.prepare.html">mysqli::prepare</a></div>
 <div class="up"><a href="class.mysqli.html">MySQLi</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div><hr /><div id="mysqli.poll" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">mysqli::poll</h1>
  <h1 class="refname">mysqli_poll</h1>
  <p class="verinfo">(PHP 5 &gt;= 5.3.0)</p><p class="refpurpose"><span class="refname">mysqli::poll</span> -- <span class="refname">mysqli_poll</span> &mdash; <span class="dc-title">Poll connections</span></p>

 </div>

 <div class="refsect1 description" id="refsect1-mysqli.poll-description">
  <h3 class="title">说明</h3>
  <p class="para">面向对象风格</p>
  <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="modifier">static</span> <span class="type">int</span> <span class="methodname"><strong>mysqli::poll</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$read</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$error</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$reject</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$sec</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$usec</code></span>
  ] )</div>

  <p class="para rdfs-comment">过程化风格</p>
  <div class="methodsynopsis dc-description">
   <span class="type">int</span> <span class="methodname"><strong>mysqli_poll</strong></span>
    ( <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$read</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$error</code></span>
   , <span class="methodparam"><span class="type">array</span> <code class="parameter reference">&$reject</code></span>
   , <span class="methodparam"><span class="type">int</span> <code class="parameter">$sec</code></span>
   [, <span class="methodparam"><span class="type">int</span> <code class="parameter">$usec</code></span>
  ] )</div>

  <p class="para rdfs-comment">
   Poll connections.
   仅可用于 <a href="book.mysqlnd.html" class="link">mysqlnd</a>。
   The method can be used as
   <a href="language.oop5.static.html" class="link">static</a>.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-mysqli.poll-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>

    
     <dt>
<em><code class="parameter">read</code></em></dt>

     <dd>

      <p class="para">
       List of connections to check for outstanding results that can be read.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">error</code></em></dt>

     <dd>

      <p class="para">
      List of connections on which an error occured, for example, query
      failure or lost connection.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">reject</code></em></dt>

     <dd>

      <p class="para">
      List of connections rejected because no asynchronous query
      has been run on for which the function could poll results.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">sec</code></em></dt>

     <dd>

      <p class="para">
       Number of seconds to wait, must be non-negative.
      </p>
     </dd>

    
    
     <dt>
<em><code class="parameter">usec</code></em></dt>

     <dd>

      <p class="para">
       Number of microseconds to wait, must be non-negative.
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-mysqli.poll-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns number of ready connections upon success, <strong><code>FALSE</code></strong> otherwise.
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-mysqli.poll-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-1646">
    <p><strong>Example #1 A <span class="function"><strong>mysqli_poll()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />$link1&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">mysqli_connect</span><span style="color: #007700">();<br /></span><span style="color: #0000BB">$link1</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">query</span><span style="color: #007700">(</span><span style="color: #DD0000">"SELECT&nbsp;'test'"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">MYSQLI_ASYNC</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$all_links&nbsp;</span><span style="color: #007700">=&nbsp;array(</span><span style="color: #0000BB">$link1</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">$processed&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">0</span><span style="color: #007700">;<br />do&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$links&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$errors&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$reject&nbsp;</span><span style="color: #007700">=&nbsp;array();<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$all_links&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$links</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$reject</span><span style="color: #007700">[]&nbsp;=&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(!</span><span style="color: #0000BB">mysqli_poll</span><span style="color: #007700">(</span><span style="color: #0000BB">$links</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$errors</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$reject</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">1</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;continue;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp;&nbsp;foreach&nbsp;(</span><span style="color: #0000BB">$links&nbsp;</span><span style="color: #007700">as&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">)&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">$result&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #0000BB">$link</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">reap_async_query</span><span style="color: #007700">())&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">print_r</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">-&gt;</span><span style="color: #0000BB">fetch_row</span><span style="color: #007700">());<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if&nbsp;(</span><span style="color: #0000BB">is_object</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">))<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">mysqli_free_result</span><span style="color: #007700">(</span><span style="color: #0000BB">$result</span><span style="color: #007700">);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;else&nbsp;die(</span><span style="color: #0000BB">sprintf</span><span style="color: #007700">(</span><span style="color: #DD0000">"MySQLi&nbsp;Error:&nbsp;%s"</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">mysqli_error</span><span style="color: #007700">(</span><span style="color: #0000BB">$link</span><span style="color: #007700">)));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: #0000BB">$processed</span><span style="color: #007700">++;<br />&nbsp;&nbsp;&nbsp;&nbsp;}<br />}&nbsp;while&nbsp;(</span><span style="color: #0000BB">$processed&nbsp;</span><span style="color: #007700">&lt;&nbsp;</span><span style="color: #0000BB">count</span><span style="color: #007700">(</span><span style="color: #0000BB">$all_links</span><span style="color: #007700">));<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

    <div class="example-contents"><p>以上例程会输出：</p></div>
    <div class="example-contents screen">
<div class="cdata"><pre>
Array
(
    [0] =&gt; test
)
</pre></div>
    </div>
   </div>
  </p>
 </div>


 <div class="refsect1 seealso" id="refsect1-mysqli.poll-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li class="member"><span class="function"><a href="mysqli.query.html" class="function" rel="rdfs-seeAlso">mysqli_query()</a> - 对数据库执行一次查询</span></li>
    <li class="member"><span class="function"><a href="mysqli.reap-async-query.html" class="function" rel="rdfs-seeAlso">mysqli_reap_async_query()</a> - Get result from async query</span></li>
   </ul>
  </p>
 </div>


</div><hr /><div class="manualnavbar" style="text-align: center;">
 <div class="prev" style="text-align: left; float: left;"><a href="mysqli.ping.html">mysqli::ping</a></div>
 <div class="next" style="text-align: right; float: right;"><a href="mysqli.prepare.html">mysqli::prepare</a></div>
 <div class="up"><a href="class.mysqli.html">MySQLi</a></div>
 <div class="home"><a href="index.html">PHP Manual</a></div>
</div></body></html>
